package controllers

import (
	"beego_background_framework/models"
	"beego_background_framework/utils"
	"github.com/astaxie/beego/orm"
)

//管理员日志
type AdminLogController struct {
	BaseController
}

func (c *AdminLogController) Index(){
	pageNo, _ := c.GetInt("page",1)
	pageSize := c.GetDefaultPageSize()
	keyword := c.GetString("keyword","")

	o := orm.NewOrm()
	//日志列表
	var list[]*models.AdminLog
	qs := o.QueryTable(new(models.AdminLog)).
		OrderBy("-id").
		Offset(c.GetPageOffset(pageNo,pageSize)).
		Limit(pageSize)
	if keyword != ""{
		cond := orm.NewCondition()
		qs = qs.SetCond(
			cond.Or("username__contains",keyword).
			Or("url__contains",keyword).
			Or("ip__contains",keyword))
	}
	//总数
	cnt,_ := qs.Count()
	_, _ = qs.All(&list)
	paginator := utils.PageUtil(int(cnt),pageSize,c.Ctx.Request.RequestURI,list)

	c.Data["list"] = list
	c.Data["paginator"] = paginator.ToString()
	c.Data["keyword"] = keyword
	c.SetTpl("admin_log/index.html")
}
